import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
export const columns: BasicColumn[] = [
  {
    title: '用户账号',
    dataIndex: 'userName',
    width: 120,
  },
  {
    title: '用户姓名',
    dataIndex: 'realName',
    width: 100,
  },
  {
    title: '头像',
    dataIndex: 'avatar',
    width: 110,
    customRender: ({text}) => {
      return render.renderAvatar({
        record: {avatar: text}
      })
    }
  },
  {
    title: '性别',
    dataIndex: 'sex',
    width: 60,
    sorter: true,
    customRender: ({text}) => {
      return render.renderDict(text, 'sys_user_sex')
    }
  },
  {
    title: '手机号',
    dataIndex: 'phone',
    width: 100,
  },

  {
    title: '状态',
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = '#55efc4'
      if (text === '2') {
        color = '#ff7f50'
      }
      return render.renderTag(render.renderDict(text, 'user_status'), color)
    },
    width: 60,
  }
];

export const recycleColumns: BasicColumn[] = [
  {
    title: '用户账号',
    dataIndex: 'userName',
    width: 100,
  },
  {
    title: '用户姓名',
    dataIndex: 'realName',
    width: 100,
  },
  {
    title: '头像',
    dataIndex: 'avatar',
    width: 80,
    customRender: ({text}) => {
      return render.renderAvatar({
        record: {avatar: text}
      })
    }
  },
  {
    title: '性别',
    dataIndex: 'sex',
    width: 80,
    sorter: true,
    customRender: ({text}) => {
      return render.renderDict(text, 'sys_user_sex')
    }
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '账号',
    field: 'userName',
    component: 'Input',
    // colProps: {span: 6}
  },
  {
    label: '手机号码',
    field: 'phone',
    component: 'Input',
    // colProps: {span: 6},
  },
  {
    label: '用户状态',
    field: 'status',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'user_status',
      placeholder:'请选择状态',
      stringToNumber:true
    },
    // colProps: {span: 6},
  }
];

export const formPasswordSchema: FormSchema[] = [
  {
    label: '用户账号',
    field: 'userName',
    component: 'Input',
    componentProps: {readonly: true}
  },
  {
    label: '',
    field: 'id',
    show: false,
    component: 'Input'
  },
  {
    label: '登录密码',
    field: 'password',
    component: 'StrengthMeter',
    componentProps: {
      placeholder: '请输入登录密码',
    },
    rules: [
      {
        required: true,
        message: '请输入登录密码',
      },
    ],
  },
  {
    label: '确认密码',
    field: 'confirmPassword',
    component: 'InputPassword',
    dynamicRules: ({values}) => rules.confirmPassword(values,true)
  }
];

export const formDetailSchema : DescItem[] = [
  {
    field: 'userName',
    label: '用户账号'
  },
  {
    field: 'nickName',
    label: '昵称'
  },
  {
    field: 'realName',
    label: '用户姓名'
  },
  {
    field: 'avatarUrl', 
    label: '头像',
    render: (curVal, data) => {
      return render.renderAvatar({
        record: {avatar: curVal}
      })
    },
  },
  {
    field: 'sex',
    label: '性别',
    render: (curVal, data) => {
      return render.renderTag(render.renderDict(curVal, 'sys_user_sex'), 'green')
    },
  },
  {
    field: 'status', 
    label: '用户状态',
    render: (curVal, data) => {
      let color = '#55efc4'
      if (curVal === '2') {
        color = '#ff7f50'
      }
      return render.renderTag(render.renderDict(curVal, 'user_status'),color)
    },
  },
  {
    field: 'phone', 
    label: '手机号码'
  },
  {
    field: 'email', 
    label: '邮箱'
  },
  {
    field: 'birthday', 
    label: '生日'
  },
  {
    field: 'createdAt',
    label: '创建时间'
  },
  {
    field: 'createdBy',
    label: '创建者'
  },
  {
    label: '备注',
    labelMinWidth: 60,
    field: 'remark',
  }
  
];
